// A lane guide for a pinball machine
//
// (c)2012 Felipe Sanches <fsanches@metamaquina.com.br>
// licensed under GPLv3 or later

module lane_guide(color="darkred"){
  //WMS part no. 03-8318-XX. Red is #03-8318-9

  x=2.3;
  height=18.3;
  length=28.55;
  thickness=1.34;
  top_thickness=2;
  width=17.71-thickness;
  attachments_height = 5.3;

  module side_walls(){
    for (i=[-1,1]){
      translate([0, thickness/2 + i*(width/2),0])
      rotate([90,0,0])
      linear_extrude(height=thickness)
      polygon(points=[[-length/2+x,0], [-length/2,height], [length/2, height], [length/2-x, 0]]);
    }
  }

  module screw_attachment_holes(){
    for (i=[-1, 1]){
      translate([i*(length/2+1.5),0,-attachments_height + height + top_thickness - 1]){
        cylinder(r=2.2, h=attachments_height+2, $fn=20);
        cylinder(r=4.7, h=attachments_height+1-thickness);
      }
    }
  }

  module top(){
    translate([0,0,height + top_thickness/2])
    cube([length, width + thickness, top_thickness], center=true);
  }

  module screw_attachments(){ 
    for (i=[-1, 1]){
      translate([i*(length/2+1.5),0,-attachments_height + height + top_thickness])
      cylinder(r=6.2, h = attachments_height);
    }
  }

  color(color){
    side_walls();
    difference(){
      union(){
        top();      
        screw_attachments();
      }
      screw_attachment_holes();
    }
  }
}

